package com.lvmama.enums;

import java.util.stream.Stream;

/**
 * 错误枚举
 * 
 * @author caoyong
 * @since 2018年1月29日 上午11:34:26
 */
public enum ErrorCodeEnum {
    UNKOWN_ERROR("500", "未知错误"),
    DATA_BASE_ACCESS_ERROR("1001", "访问数据库错误"),
    PARAMETER_CAN_NOT_BE_NULL("1002", "参数不能为空"),
    NUM_FORMATE_ERROR("1003", "数字格式化错误"),
    IO_ERROR("1005", "IO错误"),
    PROCESS_DATA_ERROR("1006", "数据处理错误"),
    SUCCESS("200","成功"),
    QUERY_ERROR("301", "查询失败"),

    //行程相关错误
    DESTINATION_NOT_EXIST("2001","目的地不存在"),
    TRAVEL_NOT_EXIST("2002","相关行程不存在"),
    ADOPT_TRAVEL_ERROR("2003","采纳行程失败"),
    REDUPLICATE_ADOPT_TRAVEL("2004","行程已采纳，不能重复采纳");
    private String code;
    private String msg;

    ErrorCodeEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    /**
     * 获得枚举
     * 
     * @param code
     * @return
     */
    public static ErrorCodeEnum getEnum(String code) {
        return Stream.of(ErrorCodeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
    }
}
